//
//  ExcelVC.swift
//  SearchHeader
//
//  Created by 万孟超 on 2023/10/13.
//

import Cocoa
import SnapKit

fileprivate let viewSize = NSMakeSize(1550, 850)

class ExcelWindowC: NSWindowController {
    convenience init(size: NSSize = viewSize, viewController: NSViewController) {
        let contentWindow = NSWindow(contentRect: NSRect(origin: .zero, size: size), styleMask: [.titled, .closable, .miniaturizable, .fullSizeContentView], backing: .buffered, defer: false)
        contentWindow.titlebarAppearsTransparent = true
        contentWindow.titleVisibility = .hidden
        contentWindow.isMovableByWindowBackground = true
        contentWindow.center()
        self.init(window: contentWindow)
        contentWindow.contentViewController = viewController
    }

    override func windowDidLoad() {
        super.windowDidLoad()
    
        // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
    }
}

class ExcelVC: BaseVC {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do view setup here.
    }
    
    private lazy var excelDataSource = SearchResult(results: [])
    
    convenience init(data: SearchResult!) {
        self.init(size: viewSize)
        self.excelDataSource = data
    }
    
    
    override func installSubViews() {
        let scrollView = NSScrollView()
        scrollView.drawsBackground = false
        
        let contentView = ExcelView(model: excelDataSource)
        scrollView.documentView = contentView
        view.addSubview(scrollView)
        scrollView.snp.makeConstraints { make in
            make.top.equalTo(30)
            make.right.equalTo(-12)
            make.left.equalTo(12)
            make.bottom.equalTo(-12)
        }
    }
    
    override func loadView() {
        let visualEffectView = NSView()
        visualEffectView.wantsLayer = true
        visualEffectView.layer?.backgroundColor = NSColor.clear.cgColor
        visualEffectView.frame = NSRect(origin: .zero, size: viewSize)
        view = visualEffectView
    }
}
